//
//
//  @ Project : AgriMarketSystem
//  @ Date : 18/10/2013
//  @ Author : NTT
//
//

using System.Collections.Generic;
using System.Linq;
using System;
namespace AgriMarketService
{
    public class SellAuction : Auction
    {
        public static List<Auction> GetAllUnfinishedAuctions()
        {
            AgriMarketDataClassesDataContext db = new AgriMarketDataClassesDataContext();
            List<Auction> result = (from tempAuction in db.Tbl_Auctions
                                    where tempAuction.TypeId == 2 && tempAuction.FinishedDate > DateTime.Now
                                    select new Auction(tempAuction.AuctionId,
                                        tempAuction.PostedDate,
                                        tempAuction.Topic,
                                        Product.GetProductById(tempAuction.ProductId),
                                        tempAuction.InitialPrice,
                                        tempAuction.ProductDescription,
                                        tempAuction.StartedDate,
                                        tempAuction.FinishedDate,
                                        tempAuction.ProductImage,
                                        tempAuction.AuthorId,
                                        TypeOfAuction.GetTypeById(tempAuction.TypeId)
                                        )).ToList();
            return result;
        }
        public static List<Auction> GetBeingAuctions()
        {
            AgriMarketDataClassesDataContext db = new AgriMarketDataClassesDataContext();
            List<Auction> result = (from tempAuction in db.Tbl_Auctions
                                    where tempAuction.TypeId == 2 && tempAuction.FinishedDate > DateTime.Now && tempAuction.StartedDate <= DateTime.Now
                                    select new Auction(tempAuction.AuctionId,
                                        tempAuction.PostedDate,
                                        tempAuction.Topic,
                                        Product.GetProductById(tempAuction.ProductId),
                                        tempAuction.InitialPrice,
                                        tempAuction.ProductDescription,
                                        tempAuction.StartedDate,
                                        tempAuction.FinishedDate,
                                        tempAuction.ProductImage,
                                        tempAuction.AuthorId,
                                        TypeOfAuction.GetTypeById(tempAuction.TypeId)
                                        )).ToList();
            return result;
        }
    }
}